﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;


namespace hw1.hw02
{
    class MainF
    {
        public static void Main3()
        {
            double Area_Sum = 0;
            Random random = new Random();
            for(int i = 1;i <= 10; i++)
            {
                if(i <= 3)
                {
                    double l = random.NextDouble() * 10 + 1;
                    double w = random.NextDouble() * 10 + 1;
                    Rectangle r = new Rectangle(l, w);
                    Area_Sum += r.Area;
                }
                else if(i <= 5)
                {
                    double a = random.NextDouble() * 10 + 1;
                    Square s = new Square(a);
                    Area_Sum += s.Area;
                }
                else if(i <= 7)
                {
                    double r = random.NextDouble() * 10 + 1;
                    Circle c = new Circle(r);
                    Area_Sum += c.Area;
                }
                else
                {
                    Triangle t;
                    do
                    {
                        double l1 = random.NextDouble() * 10 + 1;
                        double l2 = random.NextDouble() * 10 + 1;
                        double l3 = random.NextDouble() * 10 + 1;
                        t = new Triangle(l1, l2, l3);
                    } while (!t.is_Valid);
                    Area_Sum += t.Area;
                }
            }
            Console.WriteLine(Area_Sum);
        }
    }
    abstract class Shape
    {
        public abstract double Area { get; }
        public abstract bool is_Valid { get; }
    }

    class Rectangle : Shape
    {
        private double length;
        private double width;
        public double Length { get; set; }
        public double Width { get; set; }

        public override double Area
        {
            get
            {
                return length * width;
            }
        }

        public override bool is_Valid
        {
            get
            {
                return length > 0 && width > 0;
            }
        }

        public Rectangle(double l, double w)
        {
            length = l;
            width = w;
        }
    }

    class Square : Shape
    {
        private double length;

        public double Length { get; set; }

        public override double Area
        {
            get
            {
                return length * length;
            }
        }

        public override bool is_Valid
        {
            get
            {
                return length > 0;
            }
        }

        public Square(double l)
        {
            length = l;
        }
    }

    class Circle : Shape
    {
        private double diameter;

        public double Diameter { get; set; }

        public override double Area
        {
            get
            {
                return Math.PI * diameter * diameter;
            }
        }

        public override bool is_Valid
        {
            get
            {
                return diameter > 0;
            }
        }

        public Circle(double r)
        {
            diameter = r;
        }
    }

    class Triangle : Shape
    {
        private double length1, length2, length3;

        public double Length1 { get; set; }

        public double Length2 { get; set; }

        public double Length3 { get; set; }

        public override bool is_Valid
        {
            get
            {
                return length1 + length2 > length3 && length1 + length3 > length2 && length2 + length3 > length1;
            }
        }

        public override double Area
        {
            get
            {
                //海伦公式
                double s = (length1 + length2 + length3) / 2;
                return Math.Sqrt(s * (s - length1) * (s - length2) * (s - length3));
            }
        }

        public Triangle(double l1,double l2,double l3)
        {
            length1 = l1;
            length2 = l2;
            length3 = l3;
        }
    }
}
